<template>
  <div class="cate-container">
    <h1>{{ data.category.name }}</h1>
    <h2>{{ data.category.frontName }}</h2>
    <!-- 商品列表 -->
    <div class="goods" v-for="item in data.itemList" :key="item.id" @click="toGoodsDetailPageHandler(item)">
      <!-- N色可选 -->
      <div class="color" v-if="item.colorNum > 0">{{ item.colorNum }}色可选</div>
      <!-- 商品图片 -->
      <img class="image" v-lazy="item.listPicUrl" :alt="item.name">
      <img class="image-reverse" v-lazy="item.scenePicUrl" :alt="item.name">
      <!-- 促销提示语 -->
      <div class="promotion" :class="{ hide: !item.promTag }">{{ item.promTag }}</div>
      <!-- 商品名称 -->
      <div class="name">{{ item.name }}</div>
      <!-- 价格 -->
      <div class="price">{{ $t('priceSymbol') }}{{ item.retailPrice }}</div>
      <!-- 销售信息 -->
      <div class="tips">
        <hr>
        <p>{{ item.simpleDesc }}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    data: {
      type: Object,
      default: () => {}
    }
  },

  methods: {
    /**
     * 跳转到商品详情页
     * @param { Object } goods 商品信息
     */
    toGoodsDetailPageHandler (goods) {
      this.$router.push(`/goods/detail/${goods.id}`)
    }
  }
}
</script>

<style lang="less" scoped>
@import "../../styles/variable";

.cate-container {
  padding-top: 30px;
  h1 {
    font-size: 24px;
    font-weight: 700;
    line-height: 44px;
    margin-bottom: 10px;
    text-align: center;
  }
  h2 {
    color: @font-color-grey;
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    margin-bottom: 40px;
  }
  .goods {
    cursor: pointer;
    display: inline-block;
    width: 25%;
    padding: 0px 6px;
    position: relative;
    text-align: center;
    margin-bottom: 50px;
    .color {
      background-color: @bg-lightgrey;
      border: 1px solid @bg-color-golden;
      color: @bg-color-golden;
      font-size: 12px;
      position: absolute;
      top: 10px;
      left: 16px;
      height: 20px;
      border-radius: 6px;
      padding: 0 4px;
      line-height: 18px;
    }
    img {
      width: 100%;
      height: 246px;
      &.image {
        display: block;
      }
      &.image-reverse {
        display: none;
      }
    }
    &:hover {
      img {
        &.image {
          display: none;
        }
        &.image-reverse {
          display: block;
        }
      }
    }
    .promotion {
      background-color: @bg-tips;
      color: @write;
      display: inline-block;
      font-size: 12px;
      margin: 8px auto 2px;
      height: 20px;
      line-height: 20px;
      padding: 0 5px;
      &.hide {
        opacity: 0;
      }
    }
    .name {
      margin-bottom: 4px;
      height: 20px;
      line-height: 20px;
      padding: 0 10px;
    }
    .price {
      color: @color-warning;
      font-size: 13px;
      text-align: center;
      height: 20px;
      line-height: 22px;
    }
    .tips {
      hr {
        border: 0;
        border-top: 1px solid #e8e8e8;
        display: block;
        width: 130px;
        height: 1px;
        padding: 0;
        margin: 6px auto 14px;
      }
      p {
        color: @font-color-grey;
        width: 100%;
        padding: 0 10px;
        line-height: 18px;
      }
    }
  }
}
</style>
